<template>
  <div class="box">
    <!-- 为 ECharts 准备一个具备大小（宽高）的 DOM -->
    <div id="main" style="height: 600px"></div>
  </div>
</template>

<script>
import * as echarts from "echarts";

export default {
  data() {
    return {};
  },
  mounted() {
    this.getChart();
  },
  methods: {
    getChart() {
      // 基于准备好的dom，初始化echarts实例
      const myChart = echarts.init(document.getElementById("main"));

      // 指定图表的配置项和数据
      this.$ajax.get("/report/getMemberReport").then((res) => {
        myChart.setOption({
          title: {
            text: "会员数量",
          },
          tooltip: {},
          legend: {
            data: ["会员数量"],
          },
          // X轴 年、月份
          xAxis: {
            data: res.data.data.months,
          },
          yAxis: {
            type: "value",
          },
          // Y轴 会员数量
          series: [
            {
              name: "会员数量",
              type: "line",
              data: res.data.data.memberCount,
            },
          ],
        });
        this.$message.success(res.data.message);
      });
    },
  },
};
</script>

<style scoped></style>
